/**
 * 
 */
package net.phoenix.repository.query.jql;

import javax.jcr.query.InvalidQueryException;

/**
 * @author lixf
 * 
 */
public class QNameAST extends IdentifierAST {

	/**
	 * 
	 */
	private static final long serialVersionUID = -782440799556523540L;

	@Override
	public String getSelectorName() {
		return null;
	}

	@Override
	public String getPropertyName() {
		return this.getQName();
	}

	@Override
	public String getColumnName() {
		return this.getQName();
	}

	@Override
	public String getNodeTypeName() {
		return this.getQName();
	}

	@Override
	public String toJQL() {
		return this.getQName();
	}

	@Override
	public String toString() {
		return this.getQName();
	}
	@Override
	public String getQName() {
		IdentifierAST namespace = (IdentifierAST) this.getFirstChild();
		IdentifierAST name = (IdentifierAST) namespace.getNextSibling();
		return  namespace.getQName() + ":" + name.getQName();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.phoenix.repository.query.parser.JQLBaseAST#generateSQL(net.phoenix
	 * .repository.query.parser.JQLQuery)
	 */
	@Override
	public void generateSQL(JQL2SQL collector) {
		collector.push(collector.property2Column(this.getQName()));
	}

	@Override
	public void generateColumnSQL(JQL2SQL collector) throws InvalidQueryException {
		collector.push(collector.property2Column(this.getQName()) + " \"" + this.getQName()+"\"");

	}

}
